// 查询统计模块api
import Mock from 'mockjs'
const List = []
const count = 25
// const baseContent = '大厅环境咋样'
const image_uri = 'https://wpimg.wallstcn.com/e4558086-631c-425c-9430-56ffb46e70b3'
const terminalList = []
const staffList = []
for (let i = 0; i < count; i++) {
  List.push(Mock.mock({
    'id': i + 1,
    timestamp: +Mock.Random.date('T'),
    author: '@first',
    reviewer: '@first',
    title: '@title(5, 10)',
    content_short: 'mock data',
    content: '@csentence(2,8)',
    forecast: '@float(0, 100, 2, 2)',
    importance: '@integer(1, 3)',
    'type|1': ['CN', 'US', 'JP', 'EU'],
    'status|1': ['published', 'draft', 'deleted'],
    display_time: '@datetime',
    comment_disabled: true,
    pageviews: '@integer(300, 5000)',
    image_uri,
    platforms: ['a-platform']
  }))
}

for (let i = 0; i < count; i++) {
  staffList.push(Mock.mock({
    'id': i + 1,
    'headimg': 'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1574788296060&di=4fe8dbead101180d1fe8384d585639e3&imgtype=0&src=http%3A%2F%2Fb-ssl.duitang.com%2Fuploads%2Fitem%2F201804%2F15%2F20180415223814_gjrkf.jpg',
    'username': Mock.Random.cname(),
    'emp': Mock.Random.integer(1, 10000),
    'sex|1': ['男', '女'],
    'mename|1': ['机构一', '机构二', '机构三', '机构四'],
    'dep|1': ['部门一', '部门二', '部门三', '部门四'],
    'type|1': ['类型一', '类型二', '类型三', '类型四']
  }))
}

for (let i = 0; i < count; i++) {
  terminalList.push(Mock.mock({
    'id': i + 1,
    'code|1-100000': 100000,
    'size|1': ['6.0寸', '4.0寸', '5.0寸', '7.0寸'],
    'status|1': ['在线', '离线'],
    'bdwin|1': ['1号窗口', '2号窗口', '3号窗口', '4号窗口', '5号窗口'],
    'ip|1': ['192.168.1.22', '192.168.1.62', '192.168.1.122', '192.168.1.92'],
    'type|1': ['类型1', '类型2', '类型3'],
    'content': Mock.Random.ctitle(),
    adstyle: '图片',
    'adStatus|1': ['已投放', '未投放']
  }))
}

export default [
  {
    url: '/sysmanage/optionsurvey',
    type: 'get',
    response: config => {
      const { importance, type, title, page = 1, limit = 20, sort } = config.query
      let mockList = List.filter(item => {
        if (importance && item.importance !== +importance) return false
        if (type && item.type !== type) return false
        if (title && item.title.indexOf(title) < 0) return false
        return true
      })

      if (sort === '-id') {
        mockList = mockList.reverse()
      }
      const pageList = mockList.filter((item, index) => index < limit * page && index >= limit * (page - 1))
      return {
        code: 20000,
        data: {
          total: mockList.length,
          items: pageList
        }
      }
    }
  },
  {
    url: '/sysmanage/terminal',
    type: 'get',
    response: config => {
      console.log('TCL: config', config)
      const { importance, type, title, page = 1, limit = 20, sort } = config.query
      let mockList = terminalList.filter(item => {
        if (importance && item.importance !== +importance) return false
        if (type && item.type !== type) return false
        if (title && item.title.indexOf(title) < 0) return false
        return true
      })

      if (sort === '-id') {
        mockList = mockList.reverse()
      }
      const pageList = mockList.filter((item, index) => index < limit * page && index >= limit * (page - 1))
      return {
        code: 20000,
        data: {
          total: mockList.length,
          items: pageList
        }
      }
    }
  },
  {
    url: '/sysmanage/staff',
    type: 'get',
    response: config => {
      const { importance, type, title, page = 1, limit = 20, sort } = config.query
      let mockList = staffList.filter(item => {
        if (importance && item.importance !== +importance) return false
        if (type && item.type !== type) return false
        if (title && item.title.indexOf(title) < 0) return false
        return true
      })

      if (sort === '-id') {
        mockList = mockList.reverse()
      }
      const pageList = mockList.filter((item, index) => index < limit * page && index >= limit * (page - 1))
      return {
        code: 20000,
        data: {
          total: mockList.length,
          items: pageList
        }
      }
    }
  },
  {
    url: '/sysmanage/notice',
    type: 'get',
    response: config => {
      const arr = []
      for (let i = 0; i < count; i++) {
        arr.push(Mock.mock({
          'id': i + 1,
          'status|1': ['发布', '未发布'],
          'content': Mock.Random.ctitle(),
          'date': Mock.Random.date(),
          'mename|1': ['机构一', '机构二', '机构三', '机构四']
        }))
      }
      const { importance, type, title, page = 1, limit = 20, sort } = config.query
      let mockList = arr.filter(item => {
        if (importance && item.importance !== +importance) return false
        if (type && item.type !== type) return false
        if (title && item.title.indexOf(title) < 0) return false
        return true
      })

      if (sort === '-id') {
        mockList = mockList.reverse()
      }
      const pageList = mockList.filter((item, index) => index < limit * page && index >= limit * (page - 1))
      return {
        code: 20000,
        data: {
          total: mockList.length,
          items: pageList
        }
      }
    }
  },
  {
    url: '/sysmanage/adput',
    type: 'get',
    response: config => {
      const arr = []
      for (let i = 0; i < count; i++) {
        arr.push(Mock.mock({
          'id': i + 1,
          'status|1': ['已投放', '未投放'],
          'adname': Mock.Random.ctitle(),
          'date': Mock.Random.date(),
          'adtype|1': ['图片', '视频']
        }))
      }
      const { importance, type, title, page = 1, limit = 20, sort } = config.query
      let mockList = arr.filter(item => {
        if (importance && item.importance !== +importance) return false
        if (type && item.type !== type) return false
        if (title && item.title.indexOf(title) < 0) return false
        return true
      })

      if (sort === '-id') {
        mockList = mockList.reverse()
      }
      const pageList = mockList.filter((item, index) => index < limit * page && index >= limit * (page - 1))
      return {
        code: 20000,
        data: {
          total: mockList.length,
          items: pageList
        }
      }
    }
  }

]

